require(['select2', 'date','validator','jquery-form'], function() {
	var $formData = $('#formData'),$lineId = $('#lineId');
	$formData.initForm();
    var userInfo = commonFun.execParentMethod("getUserInfo");
    // console.info(userInfo);
    $("#upgradeUser").val(userInfo.name);
    var myDate = new Date();
    $("#upgradeDate").val(myDate.toLocaleString( ));

	//选择所属企业时触发事件
	$('#upg_organName').on('click', function () {
		commonFun.execParentMethod('treeDialog', {
			url: '/baseOrgan/getBaseOrganList.htm',
			name: 'organName',
			idKey: 'organId',
			pIdKey: 'parentOrganId'
		}, this, function (data) {
			if (data) {
				$lineId.html("");
				$lineId.select2('val','');
				$.ajaxExt({
					url : "/stationInfo/getBaseLineInfoList.htm",
					data:{'organId':data.organId}
				}).done(function(data) {
					var lineInfoList = data;
					var optionH = "";
					$.each(lineInfoList, function (n, lineInfo) {
						optionH = optionH + "<option value='" + lineInfo.lineId + "'>" + lineInfo.lineName + "</option>";
					});
					$lineId.append(optionH);
					$lineId.select2('val','');
				});
			}
		});
	});

	add = function(fn) {
		addOrUpdate("/upgrade/addLineMgr.htm",fn);
	};

	function addOrUpdate(url,callBack){
		var result = $.validator($formData);
		if(result){
			var $mask;
			$mask = $.createMask(window.parent.document.body);  //遮罩
			$formData.ajaxSubmit({
				dataType : 'JSON',
				success : function(result){
					$mask.remove();
					if (result && result.msgType) {
						console.info(result);
						if (result.msgType && result.msgType == '2') {
							$.messager.alert("警告", result.msg || "系统异常", "warning");
						} else if (result.msgType && result.msgType == '3') {
							$.messager.alert("错误", result.errorMsg || "系统异常", "error");
						}else if (result.msgType && result.msgType == '1') {
							callBack()
						}
					}else{

					}
				},
                error: function (data) {
					$mask.remove();
                    $.messager.alert("提示",data, "info",function(){
                        this.__closeSelf();
                    });
                }
			});
		}
	}

});